package wechat

import (
	"encoding/xml"
	"fmt"
)

type WebwxnewLoginPage struct {
	Error       xml.Name `xml:"error"`
	Ret         int      `xml:"ret"`
	Message     string   `xml:"message"`
	SKey        string   `xml:"skey"`
	WxSid       string   `xml:"wxsid"`
	WxUin       string   `xml:"wxuin"`
	PassTicket  string   `xml:"pass_ticket"`
	Isgrayscale string   `xml:"isgrayscale"`
}

type UserData struct {
	User     User             `json:"User"`
	SyncKeys SyncKeysJsonData `json:"SyncKey"`
}

type User struct {
	Uin        int64  `json:"Uin"`
	UserName   string `json:"UserName"`
	NickName   string `json:"NickName"`
	RemarkName string `json:"RemarkName"`
	Sex        int8   `json:"Sex"`
	Province   string `json:"Province"`
	City       string `json:"City"`
}

type SyncKeysJsonData struct {
	Count    int       `json:"Count"`
	SyncKeys []SyncKey `json:"List"`
}

type SyncKey struct {
	Key int64 `json:"Key"`
	Val int64 `json:"Val"`
}

func (s *SyncKeysJsonData) ToString() string {
	resultStr := ""

	for i := 0; i < s.Count; i++ {
		resultStr = resultStr + fmt.Sprintf("%d_%d|", s.SyncKeys[i].Key, s.SyncKeys[i].Val)
	}

	if len(resultStr) > 0 {
		return resultStr[:len(resultStr)-1]
	}
	return ""
}

/* 微信消息对象 */
type WxSyncMsgCollect struct {
	MsgCount int              `json:"AddMsgCount"`
	MsgList  []WxSyncMsg      `json:"AddMsgList"`
	SyncKeys SyncKeysJsonData `json:"SyncKey"`
}

/* 微信接受消息对象元素 */
type WxSyncMsg struct {
	MsgId         string                 `json:"MsgId"`
	FromUserName  string                 `json:"FromUserName"`
	ToUserName    string                 `json:"ToUserName"`
	MsgType       int                    `json:"MsgType"`
	Content       string                 `json:"Content"`
	CreateTime    int64                  `json:"CreateTime"`
	MediaId       string                 `xml:"MediaId"`
	FileName      string                 `xml:"FileName"`
	RecommendInfo WxSyncMsgRecommendInfo `json:"RecommendInfo"`
}

type WxSyncMsgRecommendInfo struct {
	NickName  string `json:"NickName"`
	Ticket    string `json:"Ticket"`
	UserName  string `json:"UserName"`
	City      string `json:"City"`
	Content   string `json:"Content"`
	Signature string `json:"Signature"`
	Sex       int    `json:"Sex"`
}

type WxUploadFile struct {
	EncryFileName string `json:"EncryFileName"`
	MediaId       string `json:"MediaId"`
	StartPos      int    `json:"StartPos"`
}

type WxFriend struct {
	MemberCount int                   `json:"MemberCount"`
	MemberList  []WxFriendContactList `json:"MemberList"`
}

type WxFriendContactList struct {
	UserName   string `json:"UserName"`
	NickName   string `json:"NickName"`
	HeadImgUrl string `json:"HeadImgUrl"`
	Signature  string `json:"Signature"`
	Province   string `json:"Province"`
	City       string `json:"City"`
	KeyWord    string `json:"KeyWord"`
}
